package com.example.hello;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;

public class Utils {
	
	public static String convertStreamToString(InputStream is) throws Exception {
	    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
	    StringBuilder sb = new StringBuilder();
	    String line = null;
	    while ((line = reader.readLine()) != null) {
	      sb.append(line).append("\n");
	    }
	    reader.close();
	    return sb.toString();
	}
	
	public static String getStringFromFile (String fileName, Context c) throws Exception {

	    StringBuilder sb = new StringBuilder();
	    try
	    {
	        BufferedReader reader = new BufferedReader(new InputStreamReader(c.getAssets().open(fileName), "UTF-8"));

	        // do reading, usually loop until end of file reading
	        String mLine = reader.readLine();
	        while(mLine != null)
	        {
	        // process line
	        sb.append(mLine + " ");
	        mLine = reader.readLine();
	        }

	        reader.close();
	    } catch(IOException e)
	    {
	        // log the exception
	        e.printStackTrace();
	    }

	    return sb.toString();
	}
}
